<?php
include('wp-blog-header.php');

$user_pod = new Pod('users');
$where = "daily_newsletter=1";
$user_pod->findRecords("id DESC", 20, $where);

echo $user_pod->getTotalRows();

$api = new PodAPI();

while($user_pod->fetchRecord()){
	$columns_newsletter['name'] = $user_pod->get_field('wp_user.user_email');
	$columns_newsletter['slug'] = sanitize_title($columns_newsletter['name']);
	$columns_newsletter['cities'] = $user_pod->get_field('city.id');
	
	$category_ids = $user_pod->get_field('categories.id');
	if(!empty($category_ids) && !is_array($category_ids)){
		$category_ids = array($category_ids);
	}
	$category_ids = implode(',',$category_ids);
	
	$columns_newsletter['categories'] = $category_ids;
	$columns_newsletter['daily'] = 1;
	$columns_newsletter['weekly'] = 1;
	$columns_newsletter['user'] = $user_pod->get_field('id');
	
	$params_newsletter = array('datatype' => 'newsletter', 'columns' => $columns_newsletter);
	printr($params_newsletter);
	$api->save_pod_item($params_newsletter);
	
	$columns_user['daily_newsletter'] = 0;
	$params_user = array('datatype' => 'users', 'tbl_row_id' => $columns_newsletter['user'], 'columns' => $columns_user);
	printr($params_user);
	$api->save_pod_item($params_user);
}
?>